package cn.dzhang.spring.boot.model;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.validation.constraints.Digits;
import javax.validation.constraints.NotNull;

import org.hibernate.validator.constraints.NotBlank;

@Entity
@Table(name = "tbl_device")
public class Device extends ModelBase implements Resource {

	private static final long serialVersionUID = -3941688691898909740L;
	@Column(length = 100, nullable = false)
	@NotBlank
	private String name;
	@NotBlank
	private String host;
	@Digits(fraction = 0, integer = 5)
	private int port;
	private boolean gateway;
	private boolean online;
	@NotNull
	@ManyToOne(cascade = CascadeType.PERSIST)
	@JoinColumn(nullable = false, name = "tbl_device_type_id")
	private DeviceType type;

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getHost() {
		return host;
	}

	public void setHost(String host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public boolean isGateway() {
		return gateway;
	}

	public void setGateway(boolean gateway) {
		this.gateway = gateway;
	}

	public boolean isOnline() {
		return online;
	}

	public void setOnline(boolean online) {
		this.online = online;
	}

	@Override
	public String getDescription() {
		return name;
	}

	public DeviceType getType() {
		return type;
	}

	public void setType(DeviceType type) {
		this.type = type;
	}

}
